from sqlalchemy import Column, Integer, String, Enum, BigInteger, SmallInteger, JSON, Numeric
from sqlalchemy.orm import relationship
from config.database import Base
from datetime import datetime

class BaMachine(Base):
    """
    机台管理表
    """

    __tablename__ = 'ba_machine'

    id = Column(Integer, primary_key=True, autoincrement=True, comment='ID')
    machine_id = Column(Integer, nullable=True, default='', comment='机台号')
    machine_name = Column(String(255), nullable=True, default='', comment='机台名称')
    CREDITS = Column(Numeric(10, 2), nullable=True, default=0, comment='真钱数')
    SCORE = Column(Numeric(10, 2), nullable=True, default=0, comment='余额')
    Probability = Column(Enum('92', '93', '94', '95', '96', '97', '98', '99', name='probability_enum'), nullable=True, default='92', comment='概率设置:92=92,93=93,94=94,95=95,96=96,97=97,98=98,99=99')
    tbIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', name='tb_index_enum'), nullable=True, default=None, comment='投币比例:0=0.1f,1=0.5f,2=1,3=2,4=5,5=10,6=50,7=100,8=200,9=500,10=1000,11=5000,12=10000')
    cpIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', name='cp_index_enum'), nullable=True, default=None, comment='彩票比例:0=1,1=2,2=5,3=10,4=50,5=100,6=200,7=500,8=1000,9=5000,10=10000')
    kfIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', name='kf_index_enum'), nullable=True, default=None, comment='开分比例:0=1,1=2,2=5,3=10,4=50,5=100,6=200,7=500,8=1000,9=5000,10=10000')
    xfIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', name='xf_index_enum'), nullable=True, default=None, comment='洗分比例:0=1,1=2,2=5,3=10,4=50,5=100,6=200,7=500,8=1000,9=5000,10=10000')
    jcIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', name='jc_index_enum'), nullable=True, default=None, comment='进钞比例:0=1,1=2,2=5,3=10,4=50,5=100,6=200,7=500,8=1000,9=5000,10=10000')
    mbIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', name='mb_index_enum'), nullable=True, default=None, comment='码表比例:0=1,1=2,2=5,3=10,4=50,5=100,6=200,7=500,8=1000,9=5000,10=10000')
    jfsxIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', name='jfsx_index_enum'), nullable=True, default=None, comment='进分上限:0=5000,1=10000,2=100000,3=200000,4=500000,5=1000000,6=2000000,7=5000000,8=10000000,9=20000000,10=50000000,11=100000000,12=200000000,13=500000000,14=1000000000')
    xtptIndex = Column(Enum('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', name='xtpt_index_enum'), nullable=True, default=None, comment='系统破台:0=5000,1=10000,2=100000,3=200000,4=500000,5=1000000,6=2000000,7=5000000,8=10000000,9=20000000,10=50000000,11=100000000,12=200000000,13=500000000,14=1000000000')
    OutChao = Column(SmallInteger, nullable=False, default=None, comment='进钞:0=有,1=无')
    OutSilver = Column(Enum('0', '1', name='out_silver_enum'), nullable=True, default=None, comment='出银模式:0=退币,1=退彩票')
    SiteType = Column(Enum('0', '1', '2', name='site_type_enum'), nullable=True, default=None, comment='场地模式:0=小,1=中,2=大')
    MachineType = Column(Enum('1', '0', name='machine_type_enum'), nullable=True, default=None, comment='是否连线:1=是连接,0=单机')
    SaleType = Column(Integer, nullable=True, default=None, comment='销售模式(0买断  1~60合作天数)')
    MinBetId = Column(Enum('0', '1', '2', '3', '4', name='min_bet_id_enum'), nullable=False, default=None, comment='最低押注:0=45,1=60,2=75,3=105,4=150')
    status = Column(SmallInteger, nullable=True, default=0, comment='状态:0=禁用,1=启用')
    is_ws_online = Column(SmallInteger, nullable=True, default=0, comment='在线状态:0=离线,1=在线')
    remark = Column(String(255), nullable=True, default='', comment='备注')
    create_time = Column(BigInteger, nullable=True, default=datetime.now().timestamp(), comment='创建时间')
    update_time = Column(BigInteger, nullable=True, default=datetime.now().timestamp(), comment='修改时间')
    BillMachine1 = Column(JSON, nullable=True, comment='')
    BillMachine2 = Column(JSON, nullable=True, comment='')
    """
    COM_ID:纸钞机Id 1~2;
    _currency1Index:面额id 0~13:
    0拒收,1面额，2面额,5面额，10面额，20面额，50面额，100面额，
    200面额，500面额，1000面额，2000面额，5000面额，10000面额
    _currencyRateIndex:面额比例id 0~11:1,2,5,10,20,50,100,200,500,1000,5000,10000
    _orderMoneyTypeIndex:纸钞机类型id 0~4:"-NULL-"，"ICT"，"UBA"，"ITL"，"MEI"
    {
        "COM_ID": 1,
        "_currency1Index": 0,
        "_currency2Index":0,
        "_currency3Index":0,
        "_currency4Index": 0,
        "_currency5Index": 0,
        "_currency6Index": 0,
        "_currency7Index": 0,
        "_currency8Index":0,
        "_currencyRateIndex":0,
        "_orderMoneyTypeIndex": 0
    }
    """

    bussiness = relationship("BaBusiness", 
                              back_populates="machine",
                              foreign_keys='[BaBusiness.m_id]')
    game_records = relationship("BaGameRecord", 
                              back_populates="machine",
                              foreign_keys='[BaGameRecord.m_id]')
    inout_records = relationship("BaInOutRecord", 
                              back_populates="machine",
                              foreign_keys='[BaInOutRecord.m_id]')